﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;


namespace teavch.Util.Formatter.SourceCode
{
	internal class CssFormatter : CodeFormatter
	{

		public CssFormatter()
		{
		}

		protected override StringBuilder Format( string input, bool quotedIdenfifiers, bool htmlBased )
		{
			StringBuilder sb = this.FormatNow( input, quotedIdenfifiers, htmlBased );
			return new StringBuilder( "<div class=\"divCssCode\" ><code>" + sb.ToString() + "</code></div>" );
		}

		private StringBuilder FormatNow( string input, bool quotedIdenfifiers, bool htmlBased )
		{
			StringBuilder result = new StringBuilder();
			CascadedStyleSheet css = new CascadedStyleSheet();
			css.LoadCss( input );
			foreach ( Style style in css.Styles )
			{
				result.Append( "<span class =\"CodeCssName\" >" + style.Name + "</span><br />" );
				result.Append( "{<br />" );
				foreach ( StyleAttribute attribute in style.StyleAttributes )
				{
					result.Append( "<span class =\"CodeCssAttributeName\" >&nbsp;&nbsp;" 
						+ attribute.AttributeName + "</span>: <span class =\"CodeCssAttributeValue\" >" 
						+ attribute.AttributeValue + "</span>;<br />" );
				}
				result.Append( "}<br /><br />" );
			}
			return result;
		}

		protected override string[] GetTokens()
		{
			string[] s = new string[] { "AttributeName", "AttributeValue" };
			return s;
		}

	}
}
